package o;

import android.content.Context;
import androidx.annotation.NonNull;
import com.huawei.appgallery.downloadengine.api.DownloadChkInfo;
import com.huawei.appgallery.downloadengine.api.SessionDownloadTask;
import com.huawei.appgallery.downloadengine.api.SplitTask;
import com.huawei.appgallery.foundation.card.base.bean.BaseDistCardBean;
import com.huawei.appgallery.foundation.store.bean.spilt.GetApksInfoRequest;
import com.huawei.appgallery.foundation.store.bean.spilt.GetApksInfoRequest.b;
import com.huawei.appgallery.foundation.store.bean.spilt.GetApksInfoResponse;
import com.huawei.appgallery.foundation.store.bean.spilt.GetApksInfoResponse.ModuleInfo;
import com.huawei.appgallery.foundation.store.bean.spilt.GetApksInfoResponse.Slice;
import com.huawei.appgallery.foundation.store.bean.spilt.GetApksInfoResponse.SplitApkInfo;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.appmarket.service.appmgr.view.activity.InstallManagerCardBean;
import java.util.ArrayList;
import java.util.List;

public class dqw {
    private c ˊ;
    private boolean ˎ = true;

    public interface c {
        void ˋ(SessionDownloadTask sessionDownloadTask);

        void ॱ();
    }

    public SessionDownloadTask ˏ(@NonNull BaseDistCardBean baseDistCardBean) {
        if (baseDistCardBean instanceof InstallManagerCardBean) {
            long ॱ = ((InstallManagerCardBean) baseDistCardBean).ॱ();
            if (ॱ > 0) {
                return dvt.ˏ().ˎ(ॱ);
            }
        }
        if (baseDistCardBean.ॱᶥ() == 0 || !cep.ˏ()) {
            SessionDownloadTask sessionDownloadTask = new SessionDownloadTask();
            sessionDownloadTask.ॱˊ(0);
            return sessionDownloadTask;
        }
        Context ˋ = ContentManager.getInstant().getContext();
        cvt ॱ2 = new b(ˋ).ˎ(baseDistCardBean.ॱـ()).ˋ().ˊ(ˊ(baseDistCardBean)).ॱ();
        ॱ2.setBlockIfProtocolNotAgreed(this.ˎ);
        ResponseBean ॱ3 = cfw.ॱ(ॱ2);
        if (ॱ3 == null || !(ॱ3 instanceof GetApksInfoResponse)) {
            return null;
        }
        GetApksInfoResponse getApksInfoResponse = (GetApksInfoResponse) ॱ3;
        if (ॱ3.getResponseCode() == 0 && ॱ3.getRtnCode_() == 0) {
            List<ModuleInfo> ˊ = getApksInfoResponse.ˊ();
            if (CollectCheck.isEmpty((List) ˊ)) {
                Logger.ˋ("AppBundleDownloadManager", "moduleInfos is empty.");
                return null;
            }
            SessionDownloadTask sessionDownloadTask2 = new SessionDownloadTask();
            sessionDownloadTask2.ʼ(baseDistCardBean.ॱـ());
            sessionDownloadTask2.ॱˊ(1);
            for (ModuleInfo ˏ : ˊ) {
                ˏ(sessionDownloadTask2, ˏ, baseDistCardBean);
            }
            return sessionDownloadTask2;
        }
        Logger.ˋ("AppBundleDownloadManager", "responseBean.getResponseCode()=" + ॱ3.getResponseCode() + " responseBean.getRtnCode_()=" + ॱ3.getRtnCode_());
        return null;
    }

    public void ˏ(@NonNull BaseDistCardBean baseDistCardBean, c cVar) {
        SessionDownloadTask ˎ;
        this.ˊ = cVar;
        if (baseDistCardBean instanceof InstallManagerCardBean) {
            long ॱ = ((InstallManagerCardBean) baseDistCardBean).ॱ();
            if (ॱ > 0) {
                ˎ = dvt.ˏ().ˎ(ॱ);
                if (this.ˊ != null) {
                    this.ˊ.ˋ(ˎ);
                    return;
                }
                return;
            }
        }
        if (baseDistCardBean.ॱᶥ() != 0 && cep.ˏ()) {
            Context ˋ = ContentManager.getInstant().getContext();
            GetApksInfoRequest ॱ2 = new b(ˋ).ˎ(baseDistCardBean.ॱـ()).ˋ().ˊ(ˊ(baseDistCardBean)).ॱ();
            ॱ2.setBlockIfProtocolNotAgreed(this.ˎ);
            ˋ(baseDistCardBean, ॱ2);
        } else if (this.ˊ != null) {
            ˎ = new SessionDownloadTask();
            ˎ.ॱˊ(0);
            this.ˊ.ˋ(ˎ);
        }
    }

    private void ˋ(@NonNull final BaseDistCardBean baseDistCardBean, GetApksInfoRequest getApksInfoRequest) {
        cfw.ˎ(getApksInfoRequest, new cgg<GetApksInfoRequest, GetApksInfoResponse>(this) {
            final /* synthetic */ dqw ˏ;

            protected /* synthetic */ void ˋ(@NonNull BaseRequest o_cvu, @NonNull ResponseBean responseBean) {
                ˎ((GetApksInfoRequest) o_cvu, (GetApksInfoResponse) responseBean);
            }

            protected void ˎ(@NonNull GetApksInfoRequest getApksInfoRequest, @NonNull GetApksInfoResponse getApksInfoResponse) {
                if (getApksInfoResponse.getResponseCode() == 0 && getApksInfoResponse.getRtnCode_() == 0) {
                    List<ModuleInfo> ˊ = getApksInfoResponse.ˊ();
                    if (CollectCheck.isEmpty((List) ˊ)) {
                        Logger.ˋ("AppBundleDownloadManager", "moduleInfos is empty.");
                        if (this.ˏ.ˊ != null) {
                            this.ˏ.ˊ.ॱ();
                            return;
                        }
                        return;
                    }
                    SessionDownloadTask sessionDownloadTask = new SessionDownloadTask();
                    sessionDownloadTask.ʼ(baseDistCardBean.ॱـ());
                    sessionDownloadTask.ॱˊ(1);
                    for (ModuleInfo ˎ : ˊ) {
                        this.ˏ.ˏ(sessionDownloadTask, ˎ, baseDistCardBean);
                    }
                    if (this.ˏ.ˊ == null) {
                        return;
                    }
                    if (CollectCheck.isEmpty(sessionDownloadTask.ᐝˊ())) {
                        Logger.ˋ("AppBundleDownloadManager", "splitTaskList is empty.");
                        this.ˏ.ˊ.ॱ();
                        return;
                    }
                    this.ˏ.ˊ.ˋ(sessionDownloadTask);
                    return;
                }
                Logger.ˋ("AppBundleDownloadManager", "responseBean.getResponseCode()=" + getApksInfoResponse.getResponseCode() + " responseBean.getRtnCode_()=" + getApksInfoResponse.getRtnCode_());
                if (this.ˏ.ˊ != null) {
                    this.ˏ.ˊ.ॱ();
                }
            }
        });
    }

    private int ˊ(@NonNull BaseDistCardBean baseDistCardBean) {
        int i = 0;
        try {
            i = Integer.parseInt(baseDistCardBean.ˎˎ());
        } catch (NumberFormatException e) {
            Logger.e("AppBundleDownloadManager", "NumberFormatException");
        }
        return i;
    }

    private SessionDownloadTask ˏ(SessionDownloadTask sessionDownloadTask, ModuleInfo moduleInfo, BaseDistCardBean baseDistCardBean) {
        List<SplitApkInfo> ˊ = moduleInfo.ˊ();
        if (CollectCheck.isEmpty((List) ˊ)) {
            Logger.ˋ("AppBundleDownloadManager", "apkInfos is empty.");
        } else {
            List arrayList = new ArrayList();
            for (SplitApkInfo splitApkInfo : ˊ) {
                SplitTask splitTask = new SplitTask();
                splitTask.ˋ(splitApkInfo.ˋ());
                splitTask.ˊ(splitApkInfo.ˏ());
                splitTask.ˊॱ(baseDistCardBean.ॱـ());
                splitTask.ˋ(splitApkInfo.ˊ());
                splitTask.ॱॱ(moduleInfo.ॱ());
                splitTask.ˎ(splitApkInfo.ˎ());
                splitTask.ᐝ(moduleInfo.ˎ());
                List ॱ = splitApkInfo.ॱ();
                if (CollectCheck.isEmpty(ॱ)) {
                    Logger.ˋ("AppBundleDownloadManager", "slices empty.");
                } else {
                    splitTask.ˋ(ˊ(ॱ));
                }
                arrayList.add(splitTask);
            }
            sessionDownloadTask.ˎ(arrayList);
        }
        return sessionDownloadTask;
    }

    private List<DownloadChkInfo> ˊ(List<Slice> list) {
        List<DownloadChkInfo> arrayList = new ArrayList();
        for (Slice slice : list) {
            DownloadChkInfo downloadChkInfo = new DownloadChkInfo();
            String[] split = slice.ॱ().split("-");
            if (split.length == 2) {
                downloadChkInfo.ˏ(Long.parseLong(split[0]));
                downloadChkInfo.ˋ(Long.parseLong(split[1]));
                downloadChkInfo.ॱ(0);
            } else {
                Logger.ˋ("AppBundleDownloadManager", "rangeInfo.length != 2.");
            }
            downloadChkInfo.ˏ(slice.ˋ());
            downloadChkInfo.ˋ(slice.ॱ());
            arrayList.add(downloadChkInfo);
        }
        return arrayList;
    }

    public static BaseDistCardBean ˊ(String str, int i, String str2) {
        BaseDistCardBean baseDistCardBean = new BaseDistCardBean();
        baseDistCardBean.ˏˎ(str);
        baseDistCardBean.ͺ(i);
        baseDistCardBean.ॱᐝ(str2);
        return baseDistCardBean;
    }

    public void ˎ(boolean z) {
        this.ˎ = z;
    }
}
